package net.esj.basic.core.engine.util.logging;

import net.esj.basic.core.engine.config.MelonConfig;

public abstract class LoggerFactory {

	public static final String MELON_LOGGER_CLASS = "melon.logger.classname";
	
	public static Logger getLogger(Class clazz){
		String classname = MelonConfig.getProperty(MELON_LOGGER_CLASS);
		Class loggerClass = null;
		try {
			loggerClass = Class.forName(classname);
		} catch (Exception e) {
		}finally{
			if(loggerClass==null){
				loggerClass = Log4jLogger.class;
			}
		}
		try {
			 Logger logger = (Logger) loggerClass.getConstructor(new Class[]{Class.class}).newInstance(clazz);
			return logger;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static Logger getLogger(String name){
		String classname = MelonConfig.getProperty(MELON_LOGGER_CLASS);
		Class loggerClass = null;
		try {
			loggerClass = Class.forName(classname);
		} catch (ClassNotFoundException e) {
		}finally{
			if(loggerClass==null){
				loggerClass = Log4jLogger.class;
			}
		}
		try {
			Logger logger = (Logger) loggerClass.getConstructor(new Class[]{String.class}).newInstance(name);
			return logger;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
}
